package com.googlecode.geoteacher.util;

import java.net.MalformedURLException;
import java.net.URL;

import android.util.Log;

public final class AssetsUtils {

	private static final String ASSET_URL_PREFIX = "file:///android_asset/";

	private AssetsUtils() {
	}

	public static URL getAssetURL(String path) throws MalformedURLException {
		return new URL(ASSET_URL_PREFIX + path);
	}

	public static boolean isAssetURL(URL url) {
		Log.i(AssetsUtils.class.getName(), "URL: " + url.toExternalForm()
				+ " path: " + url.getPath());

		return url.toExternalForm().startsWith(ASSET_URL_PREFIX);
	}

	public static String getRelativePath(URL url) {
		if (url.toString().startsWith(ASSET_URL_PREFIX)) {
			return url.toString().substring(ASSET_URL_PREFIX.length());
		} else {
			throw new IllegalArgumentException("url is not an asset url: "
					+ url.toString());
		}
	}
}
